package my.springboot.async;

import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

@Component
public class AsyncWork {
	
	@Async
	public void doWork(int i){
		System.out.println("【开始】"+i);
		try {
			Thread.sleep(1000*2);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("【结束】"+i);
	}
	
	@Async
	public Future<Integer> doWorkResult(int i){
		System.out.println("【开始】"+i);
		try {
			Thread.sleep(1000*2);
		} catch (InterruptedException e) {
			e.printStackTrace();
			return new AsyncResult<Integer>(i*-1);
		}
		System.out.println("【结束】"+i);
		return new AsyncResult<Integer>(i);
	}
	
}
